package com.example.cityiot.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cityiot.R;
import com.example.cityiot.bean.BusBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: CityIOT
 * @Package: com.example.cityiot.adapter
 * @ClassName: BusAdapter
 * @Description: java类作用描述
 * @Author: 罗文涛
 * @CreateDate: 12/30/21 11:40 AM
 */
public class BusAdapter extends BaseExpandableListAdapter {
    List<String> groupList;
    List<List<BusBean>> childList;
    Context context;

    public BusAdapter(Context context, List<String> groupList, List<List<BusBean>> childList){
        this.groupList = groupList;
        this.childList = childList;
        this.context = context;
    }
    @Override
    public int getGroupCount() {
        return groupList.size();
    }

    @Override
    public int getChildrenCount(int i) {
        return childList.get(i).size();
    }

    @Override
    public Object getGroup(int i) {
        return groupList.get(i);
    }

    @Override
    public Object getChild(int i, int i1) {
        return childList.get(i).get(i1);
    }

    @Override
    public long getGroupId(int i) {
        return i;
    }

    @Override
    public long getChildId(int i, int i1) {
        return i1;
    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.first_group_item, viewGroup,false);
        }
        TextView textView = view.findViewById(R.id.first_group_tv);
        textView.setText((String)getGroup(i));
        return view;
    }

    @Override
    public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.first_child_item, viewGroup,false);
        }
        BusBean busBean = (BusBean) getChild(i,i1);
        TextView textView = view.findViewById(R.id.first_child_tv);
        textView.setText(busBean.getName() + " " + busBean.getDistance() + "米");

        return view;
    }

    @Override
    public boolean isChildSelectable(int i, int i1) {
        return false;
    }
}
